package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.pojo.Consumer;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.mapper.ConsumerMapper;
import com.groupseven.happycampus.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("consumerService")
public class ConsumerServiceImpl implements ConsumerService {

    @Autowired
    private ConsumerMapper consumerMapper;

    @Override
    public LayuiPageVo<Consumer> consumerInformationPageDate(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);
        List<Consumer> consumers = consumerMapper.consumerInformationPageDate(params);
        PageInfo<Consumer> consumerPageInfo = new PageInfo<>(consumers);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中
        LayuiPageVo<Consumer> consumerLayuiPageVo = new LayuiPageVo<>();
        consumerLayuiPageVo.setCode(0);
        consumerLayuiPageVo.setMsg("分页列表数据");
        consumerLayuiPageVo.setCount(consumerPageInfo.getTotal()); //总记录数
        consumerLayuiPageVo.setData(consumerPageInfo.getList()); //分页的列表数据
        return consumerLayuiPageVo;
    }

    @Override
    public int addConsumer(Consumer consumer) {
        return consumerMapper.addConsumer(consumer);
    }

    @Override
    public int updateConsumerInformation(Consumer consumer) {
        return consumerMapper.updateConsumerInformation(consumer);
    }

    @Override
    public int deleteConsumer(Integer id) {
        return consumerMapper.deleteConsumer(id);
    }

    @Override
    public int deletesConsumer(String ids) {
        String[] arrId = ids.split(",");
        return consumerMapper.deletesConsumer(arrId);
    }
}
